# -*- coding: utf-8 -*-
"""
summary:
    首页文章模板
author:
    Jason Lee <huacnlee@gmail.com>
"""
from django.template import Library,defaultfilters
from utils.helper import view
from settings import *

register = Library()
__FILTER_NAME_PREFIX = "componsent_post_"
__TEMPLATE_ROOT = "components/post/%s"

def summary(post):
    """
    summary:
        列表摘要
    """
    if post == None:
        return ""

    post.summary = _format_content(post.summary,post)

    data = {
            'post' : post,
            }
    return defaultfilters.safe(view.out_html(__TEMPLATE_ROOT % ('summary.html'),data))

def _format_content(content,post):
    """
    summary:
        自动为内容的url加连接
    """
    if post.allow_auto_link:
        content = defaultfilters.urlize(content)

    return content


register.filter('%ssummary' % __FILTER_NAME_PREFIX, summary)
